<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
  <HEAD>
  <TITLE>Jena I/O Mini HowTo</TITLE>

 <LINK REL ="stylesheet" TYPE="text/css" 
	HREF="../javadoc/stylesheet.css" TITLE="Style">
 <link rel="stylesheet" type="text/css" href="../styles/doc.css" />
<style>
td { text-align:left; } 
  </style>
  </HEAD>
  <BODY>
  <h1>Jena I/O Mini HowTo</h1>
<p>
This is a guide to the I/O subsystem of Jena.
All Jena users need to know to use InputStreams and OutputStreams
rather than Readers and Writers.
The first section gives a quick introduction to the I/O subsystem.
The other sections are aimed
at users wishing to use advanced features within the I/O
subsystem.
</p>
<h2>Contents</h2>
<ul>
<li><a href="#rush">1. Quick Introduction</a>
<ul>
<li><a href="#rdfxml">1.1 RDF/XML, RDF/XML-ABBREV</a>
</li>
<li><a href="#n3">1.2 N3</a>
</li>
<li><a href="#ntriple">1.3 N-TRIPLE</a></li>
<li><a href="#turtle">1.4 TURTLE</a></li>
</ul>
<li><a href="#encoding">2. Character Encoding Issues</a>
<ul>
<li><a href="#supported-encodings">2.1 Encodings Supported in Jena 2.2 and later</a></li>
</ul>
</li>
<li><a href="#reader-writer">3. When to Use Reader and Writer?</a></li>
<li><a href="#intro-advanced">4. Introduction to Advanced Jena I/O</a></li>
<li><a href="#input">5. Advanced RDF/XML Input</a>
<ul><li><a href="#arp-properties">
5.1 ARP properties</a></li>
<li><a href="#arp-interrupt">
5.2 Interrupting ARP</a></li>
</ul></li>
<li><a href="#output">6. Advanced RDF/XML Output</a></li>
<li><a href="#n3-output">7. Advanced N3 Output</a></li>
<li><a href="#conformance">8. Conformance</a></li>
<li><a href="#speed">9. Faster RDF/XML I/O</a></li>

</ul>
<h2><a name="rush">1. Quick Introduction</a></h2>
<p>The main I/O methods in Jena use InputStream's and OutputStream's.
These methods are found on the
<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A>
interface. These are:
</p>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#read(java.io.InputStream, java.lang.String)">read</A></B>(java.io.InputStream&nbsp;in,
     java.lang.String&nbsp;base)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add statements from an RDF/XML serialization</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#read(java.io.InputStream, java.lang.String, java.lang.String)">read</A></B>(java.io.InputStream&nbsp;in,
     java.lang.String&nbsp;base,
     java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add RDF statements represented in language <code>lang</code> to the model.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#read(java.lang.String)">read</A></B>(java.lang.String&nbsp;url)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add the RDF statements from an XML document.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.OutputStream)">write</A></B>(java.io.OutputStream&nbsp;out)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Write the model as an XML document.</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.OutputStream, java.lang.String)">write</A></B>(java.io.OutputStream&nbsp;out,
      java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write a serialized represention of a model in a specified language.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.OutputStream, java.lang.String, java.lang.String)">write</A></B>(java.io.OutputStream&nbsp;out,
      java.lang.String&nbsp;lang,
      java.lang.String&nbsp;base)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write a serialized represention of a model in a specified language.</TD>
</TR>
</TABLE>
<p>The built-in languages are
<code>"RDF/XML"</code>,
<code>"RDF/XML-ABBREV"</code>,
<code>"N-TRIPLE"</code>,
<code>"N3"</code> and <code>"TURTLE"</code>.
In addition, for N3 output the language can be specified as:
<code>"N3-PP"</code>, <code>"N3-PLAIN"</code> 
or <code>"N3-TRIPLE"</code>, which controls the style of N3 produced.
</p>
<p>There are also methods which use Reader's and Writer's.
Do not use them, unless you are sure it is correct to.
In advanced applications, they are useful, see
<a href="#reader-writer">below</a>; and there
is every intention to continue to support them.
The RDF/XML parser now checks to see
if the
<code><b>Model.read(Reader &hellip;)</b></code>
calls are being abused,
and issues
<CODE><B>
<A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#ERR_ENCODING_MISMATCH">ERR_ENCODING_MISMATCH</A></B></CODE>
and
<CODE><B>
<A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#WARN_ENCODING_MISMATCH">WARN_ENCODING_MISMATCH</A></B></CODE>
errors. Most incorrect usage of Reader's for RDF/XML input will
result in such errors.
Most incorrect usage of Writer's for
RDF/XML output will produce correct XML by using an 
appropriate XML declaration
giving the encoding - e.g.
<code>&lt;?xml&nbsp;version='1.0'&nbsp;encoding='ISO-8859-15'?></code>
on my system.
However, such XML is less portable than XML in UTF-8.
Using the
<code><b>Model.write(OutputStream &hellip;)</b></code>
methods allows the Jena system code to choose UTF-8 encoding,
which is the best choice.
</p>
<h3><a name="rdfxml">1.1 RDF/XML, RDF/XML-ABBREV</a></h3>
<p>
For input, both of these are the same, and fully implement
the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/">
RDF Syntax Recommendation</a>, see
<a href="#conformance">conformance</a>.
</p>
<p>
For output, <code>"RDF/XML"</code>, produces regular output reasonably
efficiently, but it is not readable.
In contrast, <code>"RDF/XML-ABBREV"</code>, produces readable output
without much regard to efficiency.
</p>
<p>All the readers and writers for RDF/XML are
configurable, see below,
<a href="#input">input</a> and <a href="#output">output</a>.</p>
<h3><a name="n3">1.2 N3</a></h3>
<p>The N3 readers and writers implement
<a href=
"http://www.w3.org/2000/10/swap/Primer.html">Tim Berners-Lee's N3</a> language.
</p>
<p>There are actually 4 writers:</p>
  <ul>
    <li>N3: The standard writer that choose one of the other 3.</li>
    <li>N3-PP: The full N3 pretty writer</li>
    <li>N3-PLAIN: An N3 writer that does not nest bNode strutures but does write 
    record-like groups of all properties for a subject</li>
    <li>N3-TRIPLE: Writer one statement per line, like N-TRIPLES, but also does 
    qname conversion of URIrefs.</li>
  </ul>
<p>The standard Jena writer &quot;N3&quot; chooses which writer to use based on the system 
property <code>com.hp.hpl.jena.n3.N3JenaWriter.writer</code>.</p>
<p>If none of these produce N3 to your liking, it is possible
to further <a href="#n3-output">customize</a> the output.</p>
<h3><a name="ntriple">1.3 N-TRIPLE</a></h3>
<p>The N-TRIPLE readers and writers implement
<a href=
"http://www.w3.org/TR/rdf-testcases/#ntriples">RDF Core's
N-Triples</a> language. They are not configurable.</p>

<h3><a name="turtle">1.4 TURTLE</a></h3>

<p>The N3 reader accepts any valid
<a href="http://www.ilrt.bris.ac.uk/discovery/2004/01/turtle/">Turtle</a>. Note that the N3 and Turtle writers produce internationalized 
qnames, with the character set from XML Namespaces (except for ':'), not 
restricted to ASCII as is the definition of N3 and Turtle.</p>

<p>
The Turtle writer 
  is the N3 writer <a href="#n3-output">configured</a> with: usePropertySymbols=false, 
  useTripleQuotedStrings=false, useDoubles=false.
</p>
  
<h2><a name="encoding">2. Character Encoding Issues</a></h2>
<p>
The easiest way to not read or understand this section
is always to use InputStreams and OutputStreams with Jena,
and to never use Readers and Writers. If you do this, Jena
will do the right thing, for the vast majority of users.
If you have legacy code that uses Readers and Writers,
or you have special needs with respect to encodings, then
this section may be helpful.
The last part of this section summarizes the character encodings
supported by Jena.
</p>
<p>
Character encoding is the way that characters are mapped to bytes, shorts
or ints. There are many different character encodings.
Within Jena, character encodings are important in their relationship
to Web content, particularly RDF/XML files, which cannot be understood
without knowing the character encoding, and in relationship to Java,
which provides support for many character encodings.
</p>
<p>The Java approach to encodings is designed for ease of use on a single
machine, which uses a single encoding; often being a one-byte
encoding, e.g. for European languages which do not need thousands
of different characters.</p>
<p>The XML approach is designed for the Web which uses
multiple encodings, and some of them requiring thousands
of characters.</p>
<p>
On the Web, XML files, including RDF/XML files, are by default encoded
in "UTF-8" (Unicode). This is always a good choice for creating content,
and is the one used by Jena by default. Other encodings can be used,
but may be less interoperable. Other encodings should be named using the
canonical name registered at 
<a href="http://www.iana.org/assignments/character-sets">IANA</a>,
but other systems have no obligations to support any of these, other than
UTF-8 and UTF-16.
</p>
<p>
Within Java, encodings appear primarily with the 
InputStreamReader and OutputStreamWriter classes,
which convert between bytes and characters using a named encoding,
and with their subclasses,
FileReader and
FileWriter, which convert between bytes in the file
and characters using the
default encoding of the platform.
It is not possible to change the encoding used by a Reader or Writer
while it is being used.
The default encoding of the platform depends on a large range
of factors.
This default encoding may be useful for communicating with other
programs on the same platform. Sometimes the default encoding
is not registered at IANA, and so Jena application developers
should not use the default encoding for Web content, but use UTF-8.
</p>
<h3><a name="supported-encodings">2.1 Encodings Supported in Jena 2.2 and later</a></h3>
<p>
On RDF/XML input any encoding supported by Java can be used.
If this is not a canonical name registered at IANA a warning message
is produced. Some encodings have better support in Java 1.5 than Java 1.4;
for such encodings a warning message is produced on Java 1.4, suggesting
upgrading.
</p>
<p>
On RDF/XML output any encoding supported by Java can be used,
by constructing an OutputStreamWriter using that encoding,
and using that for output. If the encoding is not registered
at IANA then a warning message is produced.
Some encodings have better support in Java 1.5 than Java 1.4;
for such encodings a warning message is produced on Java 1.4, suggesting
upgrading.
</p>
<p>
Java can be configured either with or without a jar of extra encodings
on the classpath. This jar is charsets.jar and sits in the lib directory
of the Java Runtime. If this jar is not on your classpath then the range
of encodings supported is fairly small.
</p>
<p>The encodings supported by Java are listed by Sun, for
<a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">1.4.2</a>, and 
<a href="http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html">1.5.0</a>.
For an encoding that is not in these lists it is possible to write your own
transcoder as documented in the java.nio.charset package documentation.
</p>
<p>Earlier versions of Jena supported fewer encodings.</p>
<h2><a name="reader-writer">3. When to Use Reader and Writer?</a></h2>
<p>
Infrequently.
</p>
<p>
Despite the character encoding issues, 
it is still sometimes appropriate
to use Readers and Writers with Jena I/O.
A good example is using Readers and Writers into StringBuffers
in memory. These do not need to be encoded and decoded so a character
encoding does not need to be specified.
Other examples are when an advanced user explicitly wishes to
correctly control the encoding.
</p>
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#read(java.io.Reader, java.lang.String)">read</A></B>(java.io.Reader&nbsp;reader,
     java.lang.String&nbsp;base)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Using this method is often a mistake.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#read(java.io.Reader, java.lang.String, java.lang.String)">read</A></B>(java.io.Reader&nbsp;reader,
     java.lang.String&nbsp;base,
     java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Using this method is often a mistake.</TD>
</TR>

<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.Writer)">write</A></B>(java.io.Writer&nbsp;writer)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Caution! Write the model as an XML document.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.Writer, java.lang.String)">write</A></B>(java.io.Writer&nbsp;writer,
      java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Caution! Write a serialized represention of a model in a specified language.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html">Model</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/Model.html#write(java.io.Writer, java.lang.String, java.lang.String)">write</A></B>(java.io.Writer&nbsp;writer,
      java.lang.String&nbsp;lang,
      java.lang.String&nbsp;base)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Caution! Write a serialized represention of a model in a specified language.</TD>
</TR>
</TABLE>
<p>
Incorrect use of these
<code><b>read(Reader,&nbsp;&hellip;)</b></code> methods results in warnings and errors with RDF/XML and RDF/XML-ABBREV
(except in a few cases where the incorrect use cannot be automatically detected).
Incorrect use of the
<code><b>write(Writer,&nbsp;&hellip;)</b></code> methods results in
peculiar XML declarations such as <code>&lt;?xml version="1.0" encoding="WINDOWS-1252"?></code>.
This would reflect that the character encoding you used (probably without realizing)
 in your Writer is registered with IANA under the name "WINDOWS-1252".
The resulting XML is of
reduced portability
 as a result. Glenn Marcy <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4456">notes</a>:
</p>
<quote>
since UTF-8 and
UTF-16 are the only encodings REQUIRED to be understood by all conformant XML
processors, even ISO-8859-1 would technically be on shaky ground if not for the
fact that it is in such widespread use that every reasonable XML processor
supports it.
</quote>
<p>
With N-TRIPLE incorrect use is usually benign, since N-TRIPLE is ascii based.
</p>
<p>
Character encoding issues of N3 are not well-defined; hence use of these methods
may require changes in the future. Use of the InputStream and OutputStream methods
will allow your code to work with future versions of Jena which do the right thing -
whatever that is. Currently the OutputStream methods use UTF-8 encoding.
</p>
<h2><a name="intro-advanced">4. Introduction to Advanced Jena I/O</a></h2>
<p>
The RDF/XML input and output is configurable.
</p>
<p>
However, to configure it, it is necessary to access an RDFReader
or RDFWriter object that remains hidden in the
simpler interface above.
</p>
<p>The four vital calls in the Model interface are:
</p><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReader.html">RDFReader</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReaderF.html#getReader()">getReader</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return an RDFReader instance for the default serialization language.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReader.html">RDFReader</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReaderF.html#getReader(java.lang.String)">getReader</A></B>(java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return an RDFReader instance for the specified serialization language.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriter.html">RDFWriter</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriterF.html#getWriter()">getWriter</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return an RDFWriter instance for the default serialization language.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriter.html">RDFWriter</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)">getWriter</A></B>(java.lang.String&nbsp;lang)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;an RDFWriter instance for the specified serialization language.</TD>
</TR>
</TABLE>
<p>
Each of these calls returns an RDFReader or RDFWriter that can
be used to read or write any Model (not just the one
which created it).
As well as the necessary
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReader.html#read(com.hp.hpl.jena.rdf.model.Model, java.io.InputStream, java.lang.String)">read</A></B></CODE>
and
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriter.html#write(com.hp.hpl.jena.rdf.model.Model, java.io.OutputStream, java.lang.String)">write</A></B></CODE>
methods, these interfaces provide:

<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFErrorHandler.html">RDFErrorHandler</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReader.html#setErrorHandler(com.hp.hpl.jena.rdf.model.RDFErrorHandler)">setErrorHandler</A></B>(<A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFErrorHandler.html">RDFErrorHandler</A>&nbsp;errHandler)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set an error handler for the reader</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;java.lang.Object</CODE></FONT></TD>
<TD><CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReader.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(java.lang.String&nbsp;propName,
            java.lang.Object&nbsp;propValue)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the value of a reader property.</TD>
</TR>
</TABLE>
<p>Setting properties, or the error handler, on an RDFReader or an RDFWriter
allows the programmer to access non-default behaviour.
Moreover, since the RDFReader and RDFWriter is not bound to a specific
Model, a typical idiom is to create the RDFReader or RDFWriter
on system initialization, to set the appropriate properties
so that it behaves exactly as required in your system, and
then to do all subsequent I/O through it.
</p>
<pre>    Model m = Modelfactory.createDefaultModel();
    RDFWriter writer = m.getRDFWriter();
    m = null; // m is no longer needed.
    writer.setErrorHandler(myErrorHandler);
    writer.setProperty("showXmlDeclaration","true");
    writer.setProperty("tab","8");
    writer.setProperty("relativeURIs","same-document,relative");
    &hellip;
    Model marray[];
    &hellip;
    for (int i=0; i&lt;marray.length; i++) {
    &hellip;
        OutputStream out = new FileOutputStream("foo" + i + ".rdf");
        writer.write(marray[i],
                           out,
          "http://example.org/");
        out.close();
    }
</pre>
<p>
Note that all of the current implementations are
synchronized, so that a specific RDFReader cannot be
reading two different documents at the same time. In
a multihtreaded application this may suggest a need
for a pool of RDFReaders and/or RDFWriters, or
alternatively to create, initialize, use and discard them as needed.
</p>
<p>
For N-TRIPLE there are currently
no properties supported for neither the RDFReader nor
the RDFWriter. Hence this idiom above is not very helpful,
and just using the Model.write() methods may prove easier.
</p>
<p>
For RDF/XML and RDF/XML-ABBREV there are many options
in both the RDFReader and the RDFWriter.
N3 has options on the RDFWriter.

These options are detailed below.

For RDF/XML they are also found in the javadoc for

<CODE><B>JenaReader.<A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/JenaReader.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(String,&nbsp;Object)</CODE>
and
<CODE><B>RDFXMLWriterI.<A HREF="../javadoc/com/hp/hpl/jena/xmloutput/RDFXMLWriterI.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(String,&nbsp;Object)</CODE>.
</p>
<h2><a name="input">5. Advanced RDF/XML Input</a></h2>
<p>
For access to these advanced features, first
get an RDFReader object that is an instance of
an ARP parser, by using the
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFReaderF.html#getReader()">getReader</A></B>()</CODE>
method on any Model.
It is then configured using the
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/JenaReader.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(String,&nbsp;Object)</CODE>
method.
This
changes the properties for parsing RDF/XML.
Many of the properties change the RDF parser, some change the XML parser.
(The Jena RDF/XML parser, ARP,  
implements the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/#section-Infoset-Grammar">
RDF grammar</a> over a
<a href="http://xml.apache.org/xerces2-j/index.html">Xerces2-J</a> XML parser).
However, changing the features and properties of the XML parser
 is not likely to be useful, but was easy to implement.
</p>
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/JenaReader.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(String,&nbsp;Object)</CODE>
 can be used to set and get:
 <dl>
 <dt>
 ARP properties
 </dt>
 <dd>
These allow fine grain control over the extensive error reporting capabailities
of ARP. And are detailed directly below.
 </dd>
 <dt>
 SAX2 features</dt>
 <dd>
 See <a href="http://xml.apache.org/xerces2-j/features.html">Xerces features</a>.
 Value should be given as a String "true" or "false" or a Boolean.
 </dd>
 <dt>
 SAX2 properties
 </dt>
 <dd>
 See <a href="http://xml.apache.org/xerces2-j/properties.html">Xerces properties</a>.
 </dd>
 <dt>
 Xerces features
 </dt>
 <dd>
 See <a href="http://xml.apache.org/xerces2-j/features.html">Xerces features</a>.
 Value should be given as a String "true" or "false" or a Boolean.
 </dd>
 <dt>
 Xerces properties
 </dt>
 <dd>
 See <a href="http://xml.apache.org/xerces2-j/properties.html">Xerces properties</a>.
 </dd>
</dl>
<h3><a name="arp-properties">
5.1 ARP properties</a></h3>
 <p>
An ARP property is
 referred to either by its property name, (see below) or by
 an absolute URL of the form <code>http://jena.hpl.hp.com/arp/properties/&lt;PropertyName&gt;</code>.
 The value should be a String, an Integer or a Boolean depending on the property.
 <p>
 ARP property names and string values are case insensitive.
 </p>
 <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0">
 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
 <TD COLSPAN=4  style="text-align: center">
    <B>ARP Properties</B>
 </TD>
 </TR>
 <tr BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
 <th>Property Name</th>
 <th>Description</th>
 <th>Value class</th>
 <th>Legal Values</th>
 </tr>
 <tr BGCOLOR="white" CLASS="TableRowColor">
 <td><code>iri-rules</code></td>
 <td>
 Set the engine for checking and resolving. <code>&quot;strict&quot;</code> sets the IRI 
	engine with rules for valid IRIs, XLink and RDF; it does not permit spaces 
	in IRIs. <code>&quot;iri&quot; </code>sets the IRI engine to IRI (<a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 
	3986</a>, <a href="http://www.ietf.org/rfc/rfc3987.txt">RFC 3987</a>) <code>
	.</code> The default is <code>&quot;lax&quot; </code>(for backwards compatibility)<code>,</code> 
	the rules for RDF URI references only, which does permit spaces although the 
	use of spaces is not good practice.</td>
 <td>String</td>
 <td><CODE>lax</CODE><br>
	<CODE>strict</CODE><br>
	<CODE>iri</CODE></td>
 </tr>
 <tr BGCOLOR="white" CLASS="TableRowColor">
 <td><CODE>error-mode</CODE></td>
 <td>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setDefaultErrorMode()"><CODE>ARPOptions.setDefaultErrorMode()</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setLaxErrorMode()"><CODE>ARPOptions.setLaxErrorMode()</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode()"><CODE>ARPOptions.setStrictErrorMode()</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setStrictErrorMode(int)"><CODE>ARPOptions.setStrictErrorMode(int)</CODE></A><br>
This allows a coarse-grained approach to control of error handling.
Setting this property is equivalent to setting many of the fine-grained error handling
properties.
 </td>
 <td>String</td>
 <td><CODE>default</CODE><br>
 <CODE>lax</CODE><br>
 <CODE>strict</CODE><br>
 <CODE>strict-ignore</CODE><br>
 <CODE>strict-warning</CODE><br>
 <CODE>strict-error</CODE><br>
 <CODE>strict-fatal</CODE><br></td>
 </tr>
 <tr BGCOLOR="white" CLASS="TableRowColor">
 <td><CODE>embedding</CODE></td>
 <td>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setEmbedding(boolean)"><CODE>ARPOptions.setEmbedding(boolean)</CODE></A><br/>
This sets ARP to look for RDF embedded within an enclosing XML document.
 </td>
 <td>String or Boolean</td>
 <td><CODE>true</CODE> or <CODE>false</CODE></td>
 </tr>
 <tr BGCOLOR="white" CLASS="TableRowColor">
 <td>
 <code>ERR_&lt;XXX&gt;</code><br>
 <code>WARN_&lt;XXX&gt;</code><br>
 <code>IGN_&lt;XXX&gt;</code></td>
 <td>
See
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html"><CODE>ARPErrorNumbers</CODE></A>
for a complete list
of the error conditions detected.<br>
Setting one of these properties is equivalent to the method
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPOptions.html#setErrorMode(int, int)"><CODE>ARPOptions.setErrorMode(int, int)</CODE></A>.
Thus fine-grained control over the behaviour in response to specific error conditions
is possible.
 </td>
 <td>String or Integer</td>
 <td><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#EM_IGNORE"><CODE>EM_IGNORE</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#EM_WARNING"><CODE>EM_WARNING</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#EM_ERROR"><CODE>EM_ERROR</CODE></A><br>
 <A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#EM_FATAL"><CODE>EM_FATAL</CODE></A><br>
 </td>
 </tr>
 </table>
<p>
As an example, if you are working in an environment with legacy RDF data that
uses unqualified RDF attributes such as "about" instead of "rdf:about", then
the following code is appropriate:
</p>

<pre>    Model m = Modelfactory.createDefaultModel();
    RDFReader arp = m.getReader();
    m = null; // m is no longer needed.
    // initialize arp
    // Do not warn on use of unqualified RDF attributes.
    arp.setProperty("WARN_UNQUALIFIED_RDF_ATTRIBUTE","EM_IGNORE");

    &hellip;
        InputStream in = new FileInputStream(fname);
        arp.read(m,in,url);
        in.close();
</pre>
<p>As a second example, suppose you wish to work in strict mode,
but allow <code>"daml:collection"</code>, the following works:
</p>

<pre>     &hellip;
     arp.setProperty("error-mode", "strict" );
     arp.setProperty("IGN_DAML_COLLECTION","EM_IGNORE");
     &hellip;
</pre>
<p>The other way round does not work.
</p>
<pre>     &hellip;
     arp.setProperty("IGN_DAML_COLLECTION","EM_IGNORE");
     arp.setProperty("error-mode", "strict" );
     &hellip;
</pre>
<p>This is because in strict mode
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#IGN_DAML_COLLECTION">IGN_DAML_COLLECTION</A></B></CODE>
is treated as an error, and so the second call to setProperty overwrites the effect of
the first.
</p>
	<p>The IRI rules and resolver can be set on a per-reader basis:</p>
<pre>    InputStream in = ... ;
    String baseURI = ... ;
    Model model = Modelfactory.createDefaultModel();
    RDFReader r = model.getReader(&quot;RDF/XML&quot;);
    r.setProperty(&quot;iri-rules&quot;, &quot;strict&quot;) ;
    r.setProperty(&quot;error-mode&quot;, &quot;strict&quot;) ;	// Warning will be errors.</pre>
	<pre>    // Alternative to the above &quot;error-mode&quot;: set specific warning to be an error.
    //r.setProperty( "WARN_MALFORMED_URI", ARPErrorNumbers.EM_ERROR) ;
    r.read(model, in, baseURI) ;
    in.close();</pre>
	<p>The global default IRI engine can be set with:</p>
	<pre>ARPOptions.setIRIFactoryGlobal(IRIFactory.iriImplementation()) ;</pre>
	<p>or other IRI rule engine from <code>IRIFactory</code>.</p>
</p>
<h3><a name="arp-interrupt">5.2 Interrupting ARP</a></h3>
<p>
ARP can be interrupted using the 
<code>Thread.interrupt()</code> method.
This causes an 
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/ARPErrorNumbers.html#ERR_INTERRUPTED">ERR_INTERRUPTED</A></B></CODE>
error during the parse, which is usually treated as a fatal error.
</p>
<p>
Here is an illustrative code sample:
</p>
<pre>
  ARP a = new ARP();
  final Thread arpt = Thread.currentThread();
  Thread killt = new Thread(new Runnable() {
       public void run() { 
  	     try {
	        Thread.sleep(tim);
	     } catch (InterruptedException e) {
	     } 
	     arpt.interrupt();
       }
    });
  killt.start();
  try {
    in = new FileInputStream(fileName);
    a.load(in);
    in.close();
    fail("Thread was not interrupted.");
  } catch (SAXParseException e) {
  }
</pre>

<h2><a name="output">6. Advanced RDF/XML Output</a></h2>
<p>
The first RDF/XML output question is whether to use
the <code>"RDF/XML"</code> or <code>RDF/XML-ABBREV</code>
writer. While some of the code is shared,
this two writers are really very different, resulting
in different but equivalent output. <code>RDF/XML-ABBREV</code>
is slower, but should produce more readable XML.
</p>
<p>
For access to advanced features, first
get an RDFWriter object, of the appropriate language, by using
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)">getWriter</A></B>("RDF/XML")</CODE>
or
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/model/RDFWriterF.html#getWriter(java.lang.String)">getWriter</A></B>("RDF/XML-ABBREV")</CODE>
on any Model.
It is then configured using the
<CODE><B><A HREF="../javadoc/com/hp/hpl/jena/rdf/arp/JenaReader.html#setProperty(java.lang.String, java.lang.Object)">setProperty</A></B>(String,&nbsp;Object)</CODE>
method.
This
changes the properties for writing RDF/XML.
</p>
  <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0">
  <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  <TD COLSPAN=4 style="text-align: center">
	<B>Properties to Control RDF/XML Output</B>
   </TD>
  </TR>
  <tr BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
  <th>Property Name</th>
  <th>Description</th>
  <th>Value class</th>
  <th>Legal Values</th>
  </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
 <td>xmlbase</td>
 <td>The value to be included for an xml:base
 attribute on the root element in the
  file.</td><td>String</td>
 <td>a URI string, or null (default)</td></tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>longId</td>
  <td> Whether to use long or short id's for anon
  resources. Short id's are easier to read and are the default, but can run
  out of memory on very large models.</td>
 <td>String or Boolean</td>
 <td>
 "true",  "false" (default)
  </td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>allowBadURIs</td>
  <td>URIs in the graph are, by default, checked prior to
 serialization.</td>
 <td>String or Boolean</td>
 <td>
 "true",  "false" (default)
  </td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>relativeURIs</td>
 <td>
 What sort of relative URIs should be used.
 A comma separate list of options:
     <dl>
     <dt>same-document
     <dd>same-document references (e.g. "" or "#foo")
     <dt>network
     <dd>network paths e.g. "//example.org/foo" omitting the URI scheme
     <dt>absolute
     <dd>absolute paths e.g. "/foo" omitting the scheme and authority
     <dt>relative
     <dd>relative path not begining in "../"
     <dt>parent
     <dd>relative path begining in "../"
     <dt>grandparent
     <dd>relative path begining in "../../"
     </dl>
 The default value is "same-document, absolute, relative, parent".
 To switch off relative URIs use the value "".
     Relative    URIs of any of these types are output where possible if
  and only if the option has been specified.
 </td>
 <td>String</td>
 <td>&nbsp;</td>
 </tr>
   <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>showXmlDeclaration</td>
  <td>If true, an XML Declaration is included in the output, if false
   no XML declaration is included.
   The default behaviour only gives an XML Declaration when
   asked to write to an OutputStreamWriter that uses some
   encoding other than UTF-8 or UTF-16.
 In this case the encoding is shown
   in the XML declaration.
 To ensure that the encoding attribute is shown in the XML declaration
 either:
 <ul>
 <li>Set this option to true and
use the <code><b>write(Model,Writer,String)</b></code>
 variant with an appropriate OutputStreamWriter.</li>
 <li>Or set this option
 to false, and write the declaration to an OutputStream before calling
 <code><b>write(Model,OutputStream,String)</b></code>.
 </li>
 </ul>
 </td>
 <td>true, "true", false, "false" or "default"</td>
  <td>can be true, false or "default" (null)</td>
 </tr>

   <tr BGCOLOR="white" CLASS="TableRowColor">
   <td>showDoctypeDeclaration</td>
   <td>If true, an XML Doctype declaration is included in the output.
       This declaration includes a !ENTITY declaration for each
       prefix mapping in the model, and any attribute value that
       starts with the URI of that mapping is written as starting
       with the corresponding entity invocation.</td>
   <td>String or Boolean</td>
   <td>true, false, "true", "false"</td>
   </tr>

   <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>tab</td>
  <td>The number of spaces with which to indent XML child elements.</td>
 <td>String or Integer</td>
 <td>positive integer "2" is the default</td>
 </tr>
   <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>attributeQuoteChar</td>
 <td>How to write XML attributes.</td>
 <td>String</td>
 <td>"\"" or "'"</td>
 </tr>
   <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>blockRules</td>
  <td>
  A list of Resource or a String being a comma separated list
  of fragment
  IDs from
  <a href="http://www.w3.org/TR/rdf-syntax-grammar">
  http://www.w3.org/TR/rdf-syntax-grammar</a> indicating
  grammar rules that will not be used.
  Rules that can be avoided are:
  <ul>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#section-Reification"
  >section-Reification</a>  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#sectionReification"><CODE>RDFSyntax.sectionReification</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#section-List-Expand"
  >section-List-Expand</a> (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#sectionListExpand"><CODE>RDFSyntax.sectionListExpand</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeLiteralPropertyElt">parseTypeLiteralPropertyElt</a>
  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#parseTypeLiteralPropertyElt"><CODE>RDFSyntax.parseTypeLiteralPropertyElt</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeResourcePropertyElt">parseTypeResourcePropertyElt</a>
  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#parseTypeLiteralPropertyElt"><CODE>RDFSyntax.parseTypeLiteralPropertyElt</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeCollectionPropertyElt">parseTypeCollectionPropertyElt</a>
  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#parseTypeCollectionPropertyElt"><CODE>RDFSyntax.parseTypeCollectionPropertyElt</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#idAttr">idAttr</a>
  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#idAttr"><CODE>RDFSyntax.idAttr</CODE></A>)</li>
  <li><a href="http://www.w3.org/TR/rdf-syntax-grammar#propertyAttr">propertyAttr</a>
  (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/RDFSyntax.html#propertyAttr"><CODE>RDFSyntax.propertyAttr</CODE></A>)</li>
  </ul>
  In addition "daml:collection" (<A HREF="../javadoc/com/hp/hpl/jena/vocabulary/DAML_OIL.html#collection"><CODE>DAML_OIL.collection</CODE></A>)
  can be blocked. Blocking <a href=
  "http://www.w3.org/TR/rdf-syntax-grammar#idAttr">idAttr</a>  also blocks
  <a href="http://www.w3.org/TR/rdf-syntax-grammar#section-Reification"
  >section-Reification</a>.
  By default, rule
  <a href="http://www.w3.org/TR/rdf-syntax-grammar#propertyAttr">propertyAttr</a>
  is blocked.
  For the basic writer (RDF/XML) only
  <a href="http://www.w3.org/TR/rdf-syntax-grammar#parseTypeLiteralPropertyElt">parseTypeLiteralPropertyElt</a>
  has any affect, since none of the other rules are implemented by that writer.
 </td><td>Resource[] or String</td><td>&nbsp;</td>

  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>prettyTypes</td>
  <td>Only for the RDF/XML-ABBREV writer.
 This is a list of
  the types of the principal objects in the model.  The writer
   will tend to create RDF/XML with resources of these types at the
   top level.
  <br />
  Example usage showing the a value suitable for DAML+OIL output:
   <pre>  w.setProperty("prettyTypes",
           new Resource[]{
                DAML_OIL.Ontology,
                DAML_OIL.Class,
                DAML_OIL.Datatype,
                DAML_OIL.Property,
                DAML_OIL.ObjectProperty,
                DAML_OIL.DatatypeProperty,
                DAML_OIL.TransitiveProperty,
                DAML_OIL.UnambigousProperty,
                DAML_OIL.UniqueProperty,
                });
   </pre>
   </td><td>Resource[]</td><td>&nbsp;</td>
 </tr>
 </table>

<p>
As an example,
</p>
<pre>     RDFWriter w = m.getWriter("RDF/XML-ABBREV");
     w.setProperty("attribtueQuoteChar","'");
     w.setProperty("showXMLDeclaration","true");
     w.setProperty("tab","1");
     w.setProperty("blockRules",
       "daml:collection,parseTypeLiteralPropertyElt,"
       +"parseTypeResourcePropertyElt,parseTypeCollectionPropertyElt");
</pre>
<p>creates a writer that does not use rdf:parseType (preferring rdf:datatype for
rdf:XMLLiteral), indents only a little, and produces the XMLDeclaration. Attributes
are used, and are quoted with "'".</p>

<p>Note that property attributes are not used at all, by default.
However, the RDF/XML-ABBREV writer includes a rule to produce property attributes
when the value does not contain any spaces. This rule is normally
switched off.
 This rule can be turned on
  selectively by using the blockRules property as detailed above.
  </p>


<h2><a name="n3-output">7. Advanced N3 Output</a></h2>
<p>The N3 pretty printer (which is used by default)&nbsp; and the N3 plain 
writer provide a number of properties to control their output.&nbsp; The 
properties all start: <code>http://jena.hpl.hp.com/n3/properties/</code>. The 
name used can be the full name, starting with this string, or the short form of 
just the name below.&nbsp; All 
values are strings; they may be interpreted as integer, boolean or string as 
defined below.</p>
  <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0">
  <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
  <TD COLSPAN=4 style="text-align: center">
    <B>Properties to Control N3 Output</B>
  </TD>
  </TR>
  <tr BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
  <th>Property Name</th>
  <th>Description</th>
  <th>Default</th>
  <th>Legal Values of String</th>
  </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
 <td>minGap</td>
 <td>Minimum gap between items on a line</td>
 <td>
 <p align="center">1</td>
 <td>positive integer</td></tr>
  <tr>
  <td>objectLists</td>
 <td>
 Print object lists as comma separated lists</td>
 <td align="center">
 <p style="text-align: center">true</td>
 <td>
 boolean &quot;true&quot; or &quot;false&quot;</td>
  </tr>
  <tr>
  <td>subjectColumn</td>
 <td>
 If the subject is shorter than this value, the first property may go on the same 
 line.</td>
 <td align="center">
 indentProperty</td>
 <td>
 positive integer</td>
  </tr>
  <tr>
  <td>propertyColumn</td>
  <td>Width of the property column</td>
  <td align="center" style="text-align: center">8</td>
 <td>
 positive integer</td>
  </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>indentProperty</td>
  <td> Width to indent properties</td>
  <td align="center" style="text-align: center"> 6</td>
 <td>
 positive integer</td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>widePropertyLen</td>
  <td> Width of the property column </td>
  <td align="center" style="text-align: center"> 20</td>
 <td>
 integer, greater than propertyColumn</td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>abbrevBaseURI</td>
  <td> Control whether to use abbreviations <code>&lt;&gt;</code> or <code>&lt;#&gt;</code></td>
  <td align="center" style="text-align: center"> true</td>
 <td>
 boolean &quot;true&quot; or &quot;false&quot;</td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>usePropertySymbols</td>
  <td> Control whether to use &quot;a&quot;, &quot;=&quot; and &quot;=&gt;&quot; in output</td>
  <td align="center" style="text-align: center"> true</td>
 <td>
 boolean &quot;true&quot; or &quot;false&quot;</td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>useTripleQuotedStrings</td>
  <td> Allow the use of &quot;&quot;&quot; to delimit long strings</td>
  <td align="center" style="text-align: center"> true</td>
 <td>
 boolean &quot;true&quot; or &quot;false&quot;</td>
 </tr>
  <tr BGCOLOR="white" CLASS="TableRowColor">
  <td>useDoubles</td>
  <td> Allow the use doubles as 123.456</td>
  <td align="center" style="text-align: center"> true</td>
 <td>
 boolean &quot;true&quot; or &quot;false&quot;</td>
 </tr>
 </table>

<p>Notes:</p>
  <ol>
    <li>Only the N3 pretty printer print object lists as comma separated lists.</li>
  </ol>


<h2><a name="conformance">8. Conformance</a></h2>
<p>The RDF/XML I/O endeavours to conform with the
<a href="http://www.w3.org/TR/rdf-syntax-grammar/">
RDF Syntax Recommendation</a>.</p>
<p>The parser must be set to strict mode.
(Note that, the conformant behaviour for
<code>rdf:parseType="daml:collection"</code>
is to silently turn
<code>"daml:collection"</code> into <code>"Literal"</code>).
</p>
<p>The RDF/XML writer is conformant. But does not exercise
much of the grammar.
</p>
<p>
The RDF/XML-ABBREV writer  exercises all of the
grammar and is conformant except
that it uses the "daml:collection" construct for DAML ontologies.
This non-conformant behaviour can be switched off using the
"blockRules" property.</p>
<p>To create such conformant readers and writers use the following:
</p>
<pre>   Model m;
   &hellip;
   RDFReader conformantParser = m.getReader();
   conformantParser.setProperty("error-mode","strict");
   &hellip;
   RDFWriter conformantAbbrevWriter = m.getWriter("RDF/XML-ABBREV");
   conformantAbbrevWriter.setProperty("blockRules","daml:collection");
</pre>
<h2><a name="speed">9. Faster RDF/XML I/O</a></h2>
<p>
To optimise the speed of writing RDF/XML it is suggested that
all URI processing is turned off. Also do not use RDF/XML-ABBREV.
It is unclear whether the longId attribute is faster or slower;
the short IDs have to be generated on the fly and a table maintained
during writing. The longer IDs are long, and hence take longer to write.
The following creates a faster writer:
</p>
<pre>   Model m;
   &hellip;
   &hellip;
   RDFWriter fasterWriter = m.getWriter("RDF/XML");
   fasterWriter.setProperty("allowBadURIs","true");
   fasterWriter.setProperty("relativeURIs","");
   fasterWriter.setProperty("tab","0");
</pre>

<p>
When reading RDF/XML the check for reuse of rdf:ID has a
memory overhead, which can be significant for very large files.
In this case, this check can be suppressed by telling ARP to ignore 
this error.
</p>
<pre>   Model m;
   &hellip;
   &hellip;
   RDFReader bigFileReader = m.getReader("RDF/XML");
   bigFileReader.setProperty("WARN_REDEFINITION_OF_ID","EM_IGNORE");
   &hellip;
</pre>



 </BODY>
</HTML>
